Trapping Rain Water

Hard

Question

Given a list of non-negative integers representing the heights of walls, calculate the total amount of water that can be trapped after a rainfall.

Trapping Rain Water Example 1

Input: walls = [4, 2, 0, 3, 2, 3, 1]

Output: 5

Trapping Rain Water Example 2

Input: walls = [3, 1, 5, 2, 4, 2, 1]

Output: 4

Clarify the problem

What are some questions you'd ask an interviewer?

Understand the problem

Given the walls map [0, 1, 0, 2, 0, 1], how much water can be trapped after rain?
1 unit of water
2 units of water
3 units of water
4 units of water

Login or signup to save your code.

Notes